<?php

namespace app\store\model;

use think\Model;

/**用户登录模型
 * Class UserLoginModel
 * @package app\store\model
 */
class UserLoginModel extends Model
{
    protected $connection = 'db_platform_log';

    protected $table = 'user_score_log';

    /**获取指定时间的登录用户
     * @param $where_time
     * @return array
     */
    public static function getUserIds($where_time)
    {
        $data = self::table('qplogdb.user_inout_log')
        ->where('RecordTime', 'between', $where_time)
            ->where('Type', UserSignLogModel::LOGIN_TYPE)
            ->column('distinct(UserID) as user_id');

        return $data;
    }


    /**获取指定时间的登录用户的子查询语句
     * @param $where_time
     * @return string
     * @throws \think\exception\DbException
     */
    public static function getUserIdsSubSql($where_time)
    {
        $sql = self::table('qplogdb.user_inout_log')
            ->where('RecordTime', 'between', $where_time)
            ->where('Type', UserSignLogModel::LOGIN_TYPE)
            ->fieldRaw('distinct(UserID)')
            ->buildSql();

        return $sql;
    }

}